home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / drop-shadow.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  5.8 KB  |  179 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.  
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ;
  16. ; drop-shadow.scm   version 1.04   1999/12/21 
  17. ;
  18. ; CHANGE-LOG:
  19. ; 1.00 - initial release
  20. ; 1.01 - fixed the problem with a remaining copy of the selection
  21. ; 1.02 - some code cleanup, no real changes
  22. ; 1.03 - can't call gimp-edit-fill until layer is added to image!
  23. ;
  24. ;
  25. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  26. ;  
  27. ; Adds a drop-shadow of the current selection or alpha-channel. 
  28. ;
  29. ; This script is derived from my script add-shadow, which has become 
  30. ; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his 
  31. ; idea to add alpha-support to add-shadow.
  32.  
  33.   
  34. (define (script-fu-drop-shadow image
  35.                    drawable
  36.                    shadow-transl-x
  37.                    shadow-transl-y
  38.                    shadow-blur
  39.                    shadow-color
  40.                    shadow-opacity
  41.                    allow-resize)
  42.   (let* ((shadow-blur (max shadow-blur 0))
  43.      (shadow-opacity (min shadow-opacity 100))
  44.      (shadow-opacity (max shadow-opacity 0))
  45.      (type (car (gimp-drawable-type-with-alpha drawable)))
  46.      (image-width (car (gimp-image-width image)))
  47.      (image-height (car (gimp-image-height image)))
  48.      (from-selection 0)
  49.      (active-selection 0)
  50.      (shadow-layer 0))
  51.  
  52.     (gimp-context-push)
  53.  
  54.     (gimp-image-set-active-layer image drawable)
  55.  
  56.     (gimp-image-undo-group-start image)
  57.   
  58.     (gimp-layer-add-alpha drawable)
  59.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  60.     (begin
  61.       (gimp-selection-layer-alpha drawable)
  62.       (set! from-selection FALSE))
  63.     (begin
  64.       (set! from-selection TRUE)
  65.       (set! active-selection (car (gimp-selection-save image)))))
  66.  
  67.     (let* ((selection-bounds (gimp-selection-bounds image))
  68.        (select-offset-x (cadr selection-bounds))
  69.        (select-offset-y (caddr selection-bounds))
  70.        (select-width (- (cadr (cddr selection-bounds)) select-offset-x))
  71.        (select-height (- (caddr (cddr selection-bounds)) select-offset-y))
  72.   
  73.        (shadow-width (+ select-width (* 2 shadow-blur)))
  74.        (shadow-height (+ select-height (* 2 shadow-blur)))
  75.        
  76.        (shadow-offset-x (- select-offset-x shadow-blur))
  77.        (shadow-offset-y (- select-offset-y shadow-blur)))
  78.  
  79.       (if (= allow-resize TRUE)
  80.       (let* ((new-image-width image-width)
  81.          (new-image-height image-height)
  82.          (image-offset-x 0)
  83.          (image-offset-y 0))
  84.  
  85.         (if (< (+ shadow-offset-x shadow-transl-x) 0)
  86.         (begin
  87.           (set! image-offset-x (- 0 (+ shadow-offset-x
  88.                            shadow-transl-x)))
  89.           (set! shadow-offset-x (- 0 shadow-transl-x))
  90.           (set! new-image-width (- new-image-width image-offset-x))))
  91.  
  92.         (if (< (+ shadow-offset-y shadow-transl-y) 0)
  93.         (begin
  94.           (set! image-offset-y (- 0 (+ shadow-offset-y
  95.                            shadow-transl-y)))
  96.           (set! shadow-offset-y (- 0 shadow-transl-y))
  97.           (set! new-image-height (- new-image-height image-offset-y))))
  98.  
  99.         (if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x)
  100.            new-image-width)
  101.         (set! new-image-width
  102.               (+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
  103.  
  104.         (if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y)
  105.            new-image-height)
  106.         (set! new-image-height
  107.               (+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
  108.  
  109.         (gimp-image-resize image
  110.                    new-image-width
  111.                    new-image-height
  112.                    image-offset-x
  113.                    image-offset-y)))
  114.  
  115.       (set! shadow-layer (car (gimp-layer-new image
  116.                           shadow-width
  117.                           shadow-height
  118.                           type
  119.                           "Drop-Shadow"
  120.                           shadow-opacity
  121.                           NORMAL-MODE)))
  122.       (gimp-image-add-layer image shadow-layer -1)
  123.       (gimp-layer-set-offsets shadow-layer
  124.                   shadow-offset-x
  125.                   shadow-offset-y))
  126.  
  127.     (gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
  128.     (gimp-context-set-background shadow-color)
  129.     (gimp-edit-fill shadow-layer BACKGROUND-FILL)
  130.     (gimp-selection-none image)
  131.     (gimp-layer-set-preserve-trans shadow-layer FALSE)
  132.     (if (>= shadow-blur 1.0) (plug-in-gauss-rle 1
  133.                         image
  134.                         shadow-layer
  135.                         shadow-blur
  136.                         TRUE
  137.                         TRUE))
  138.     (gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
  139.  
  140.     (if (= from-selection TRUE)
  141.     (begin
  142.       (gimp-selection-load active-selection)
  143.       (gimp-edit-clear shadow-layer)
  144.       (gimp-image-remove-channel image active-selection)))
  145.  
  146.     (if (and
  147.      (= (car (gimp-layer-is-floating-sel drawable)) 0)
  148.      (= from-selection FALSE))
  149.     (gimp-image-raise-layer image drawable))
  150.  
  151.     (gimp-image-set-active-layer image drawable)
  152.     (gimp-image-undo-group-end image)
  153.     (gimp-displays-flush)
  154.  
  155.     (gimp-context-pop)))
  156.  
  157. (script-fu-register "script-fu-drop-shadow"
  158.             _"_Drop-Shadow..."
  159.             "Add a drop-shadow of the current selection or alpha-channel"
  160.             "Sven Neumann <sven@gimp.org>"
  161.             "Sven Neumann"
  162.             "1999/12/21"
  163.             "RGB* GRAY*"
  164.             SF-IMAGE       "Image"          0
  165.             SF-DRAWABLE    "Drawable"       0
  166.             SF-ADJUSTMENT _"Offset X"       '(8 -4096 4096 1 10 0 1)
  167.             SF-ADJUSTMENT _"Offset Y"       '(8 -4096 4096 1 10 0 1)
  168.             SF-ADJUSTMENT _"Blur radius"    '(15 0 1024 1 10 0 1)
  169.             SF-COLOR      _"Color"          '(0 0 0)
  170.             SF-ADJUSTMENT _"Opacity"        '(80 0 100 1 10 0 0)
  171.             SF-TOGGLE     _"Allow resizing" TRUE)
  172.  
  173. (script-fu-menu-register "script-fu-drop-shadow"
  174.              _"<Image>/Script-Fu/Shadow")
  175.